In [ ]:
from IPython.html import widgets
from IPython.display import display
from d3networkx import ForceDirectedGraph, EventfulGraph
In [ ]:
G = EventfulGraph()
d3 = ForceDirectedGraph(G)
display(d3)
The following code creates an animation of some of the plot's properties.
In [ ]:
# Redisplay
display(d3)
import time
G.node.clear()
G.add_node(1, fill="red", stroke="black", color='black', label='A')
time.sleep(1.0)
G.add_node(2, fill="gold", stroke="black", color='black', r=20, font_size='24pt', label='B')
time.sleep(1.0)
G.add_node(3, fill="green", stroke="black", color='white', label='C')
time.sleep(1.0)
G.add_edges_from([(1,2),(1,3), (2,3)], stroke="#aaa", strokewidth="1px", distance=200, strength=0.5)
time.sleep(1.0)
G.adj[1][2]['distance'] = 20
time.sleep(1.0)
G.adj[1][3]['distance'] = 20
time.sleep(1.0)
G.adj[2][3]['distance'] = 20
time.sleep(1.0)
G.node[1]['r'] = 16
time.sleep(0.3)
G.node[1]['r'] = 8
G.node[2]['r'] = 16
time.sleep(0.3)
G.node[2]['r'] = 20
G.node[3]['r'] = 16
time.sleep(0.3)
G.node[3]['r'] = 8
G.node[1]['fill'] = 'purple'
time.sleep(0.3)
G.node[1]['fill'] = 'red'
G.node[2]['fill'] = 'purple'
time.sleep(0.3)
G.node[2]['fill'] = 'gold'
G.node[3]['fill'] = 'purple'
time.sleep(0.3)
G.node[3]['fill'] = 'green'
time.sleep(1.0)
G.node.clear()